package com.sxpcwlkj.sxpcwlkj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxpcwlkj.common.utils.MapstructUtils;
import com.sxpcwlkj.framework.entity.page.PageQuery;
import com.sxpcwlkj.framework.entity.page.TableDataInfo;
import com.sxpcwlkj.framework.mapper.BaseMapperPlus;
import com.sxpcwlkj.framework.sercice.impl.BaseServiceImpl;
import com.sxpcwlkj.sxpcwlkj.entity.StoreMember;
import com.sxpcwlkj.sxpcwlkj.entity.bo.StoreMemberBo;
import com.sxpcwlkj.sxpcwlkj.entity.vo.StoreMemberVo;
import com.sxpcwlkj.sxpcwlkj.mapper.StoreMemberMapper;
import com.sxpcwlkj.sxpcwlkj.service.StoreMemberService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;


/**
 * 会员管理
 *
 * @author 西决 942879858@qq.com
 * @since 1.0.0 2024-05-13
 */
@Slf4j
@Service("store_member")
@RequiredArgsConstructor
public class StoreMemberServiceImpl extends BaseServiceImpl<StoreMember, StoreMemberVo,StoreMemberBo> implements StoreMemberService {

   private final StoreMemberMapper baseMapper;


    @Override
    public BaseMapperPlus<StoreMember, StoreMemberVo> getBaseMapper() {
        return baseMapper;
    }


    @Override
    public Boolean insert(StoreMemberBo bo) {
        int row = 0;
        StoreMember obj = MapstructUtils.convert(bo, StoreMember.class);
        row = this.getBaseMapper().insert(obj);
        return row > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(Serializable id) {
        return this.getBaseMapper().deleteById(id) > 0;
    }

    @Override
    public Boolean updateById(StoreMemberBo bo) {
        int row = 0;
        StoreMember obj = MapstructUtils.convert(bo, StoreMember.class);
        row = this.getBaseMapper().updateById(obj);
        return row > 0;
    }

    @Override
    public StoreMemberVo selectVoById(Serializable id) {
        return this.getBaseMapper().selectVoById(id);
    }


    @Override
    public TableDataInfo<StoreMemberVo> selectListVoPage(StoreMemberBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<StoreMember> lqw = buildQueryWrapper(bo);
        Page<StoreMemberVo> page = baseMapper.selectVoPage(pageQuery.build(),lqw);
        return TableDataInfo.build(page);
    }


    private LambdaQueryWrapper<StoreMember> buildQueryWrapper(StoreMemberBo query){
        if(query==null){
            query=new StoreMemberBo();
        }
        //Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<StoreMember> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

}
